// Copyright DustedPixels.com 2008. All rights reserved.

package com.dustedpixels.common.base;

/**
 * @author micapolos@gmail.com (Michal Pociecha-Los)
 */
public final class References {
  /**
   * Returns new empty reference.
   * 
   * @param <T> 
   * @return new reference
   */
  public static <T> Reference<T> newEmpty() {
    return new ReferenceImpl<T>(null);
  }
 
  /**
   * Returns new reference initially referencing given object.
   * 
   * @param <T> 
   * @param object initially referenced object
   * @return new reference
   */
  public static <T> Reference<T> newWith(T object) {
    return new ReferenceImpl<T>(object);
  }
 
  /**
   * Base implementation of {@code Reference}.
   */
  private static final class ReferenceImpl<T> implements Reference<T> {
    private T object;
    
    public ReferenceImpl(T object) {
      this.object = object;
    }
    
    public T get() {
      return object;
    }

    public void set(T object) {
      this.object = object;
    }
  }
}
